//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chris.impl;

import com.chris.entity.content;
import com.chris.utils.DbConnection;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

public class contentImpl {
    private final QueryRunner runner = new QueryRunner();

    public contentImpl() {
    }

    public List<content> search(String params, String args) throws SQLException {
        String sql = "select * from content where " + params + " like '%" + args + "%'";
        Connection connection = DbConnection.getConnection();
        return this.runner.query(connection, sql, new BeanListHandler<>(content.class));
    }

    public List<content> getByID(int id) throws SQLException {
        Connection connection = DbConnection.getConnection();
        String sql = "select * from content where journal_id=?";
        return this.runner.query(connection, sql, new BeanListHandler<>(content.class), id);
    }

    public content getByContentID(int id) {
        String sql = "select * from content where content_id = ?";
        Connection connection = DbConnection.getConnection();

        try {
            return this.runner.query(connection, sql, new BeanHandler<>(content.class), id);
        } catch (SQLException var5) {
            var5.printStackTrace();
            return null;
        }
    }

    public long getSize() throws SQLException {
        Connection connection = DbConnection.getConnection();
        String sql = "select count(*) from content";
        return this.runner.query(connection, sql, new ScalarHandler<>());
    }

    public void insert(int journal_id, long content_id, String paper_title, String author, String keyword, String page_number) throws SQLException {
        Connection connection = DbConnection.getConnection();
        String sql = "insert into content values(?,?,?,?,?,?)";
        this.runner.execute(connection, sql, journal_id, content_id, paper_title, author, keyword, page_number);
    }
    public List<content>getAll() throws SQLException{
        String sql = "select * from content";
        Connection connection = DbConnection.getConnection();
        return runner.query(connection,sql,new BeanListHandler<>(content.class));
    }
}
